package com.datang.petstore.service.impl;


import com.datang.petstore.entity.PetMold;
import com.datang.petstore.entity.PetMoldExample;
import com.datang.petstore.generatemapper.PetMoldMapper;
import com.datang.petstore.service.PetMoldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-10-30 14:58
 * @notify宠物类型
 * @version 1.0
 */
@Service
public class PetMoldServiceImpl implements PetMoldService {

    @Autowired
    private PetMoldMapper petMoldMapper;

    /*
     * @author 顶风少年
     * @date 2019/10/30 15:02
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @result com.datang.petstore.utils.Result
     * @notify 获取全部宠物的类型
     * version 1.0
     */
    @Cacheable(value = "getAllPetMold",key="1" )
    public List<PetMold> getAllPetMold() {
        PetMoldExample petMoldExample = new PetMoldExample();
        return petMoldMapper.selectByExample(petMoldExample);
    }

    /*
     * @author 顶风少年
     * @date 2019/11/19 11:19
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @param petMold
     * @result void
     * @notify 添加宠物类型
     * version 1.0
     */
    @CacheEvict(value = "getAllPetMold",key="1" )
    @Transactional
    public void addPetMold(PetMold petMold) {
        petMold.setDate(new Date());
        petMoldMapper.insert(petMold);
    }


    /*
     * @author 顶风少年
     * @date 2019/11/19 11:19
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @param petMold
     * @result void
     * @notify 删除宠物类型
     * version 1.0
     */
    @CacheEvict(value = "getAllPetMold",key="1" )
    @Transactional
    public void deletePetMold(Integer id) {
        petMoldMapper.deleteByPrimaryKey(id);
    }

    /*
     * @author 顶风少年
     * @date 2019/11/19 11:19
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @param petMold
     * @result void
     * @notify 修改宠物类型
     * version 1.0
     */
    @CacheEvict(value = "getAllPetMold",key="1" )
    @Transactional
    public void updatePetMold(PetMold petMold) {
        petMold.setDate(new Date());
        petMoldMapper.updateByPrimaryKeySelective(petMold);
    }
}
